package com.ruoyi.web.controller;

import com.ruoyi.business.UrlPass;
import com.ruoyi.business.ao.UrlPassAO;
import com.ruoyi.business.service.UrlPassService;
import com.ruoyi.common.common.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @title: CustomerController
 * @copyright: copyright (c) 2021
 * @author: jiangguanjun
 * @date: 2023/1/29 14:56
 * @firstReview:
 * @lastReview:
 * @desc: 系统后台相关
 */
@Api(value = "SystemController", tags = "系统后台相关，暂时不需要联调")
@RestController
@Slf4j
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private UrlPassService urlPassService;


    @PostMapping("/pass/add")
    @ApiOperation(value = "放行接口添加")
    public ResultBody passAdd(@RequestBody UrlPassAO urlPassAO){
        // 该处暂时先校验字符串匹配，后期上短信功能发送短信给超级管理员
        if(!urlPassAO.getPassword().equals("SMroyLftY_Pl.w8iVJok")){
            return ResultBody.error("添加放行接口失败") ;
        }

        boolean exist = urlPassService.isContainPass(urlPassAO.getUrl(),urlPassAO.getReqType()) ;
        if(exist){
            return ResultBody.error("该接口已经存在") ;
        }

        UrlPass urlPass = new UrlPass() ;
        BeanUtils.copyProperties(urlPassAO,urlPass);
        return urlPassService.add(urlPass) ;
    }




}
